package com.helloae.chap06;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory;
import com.esri.arcgis.datasourcesraster.IRasterWorkspace;
import com.esri.arcgis.datasourcesraster.IRasterWorkspaceProxy;
import com.esri.arcgis.datasourcesraster.RasterWorkspaceFactory;
import com.esri.arcgis.geoanalyst.RasterConversionOp;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geodatabase.IGeoDataset;
import com.esri.arcgis.geodatabase.IRasterDataset;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;

/**
 * 将GRID转换为shp文件<br>
 * 示例章节：6.5.3
 * @author zhushijie
 *
 */
public class RasterToShapefile {

	public static void main(String[] args) throws UnknownHostException, IOException {
		EngineInitializer.initializeEngine();
		AoInitialize ao = new AoInitialize();
		ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
		
		//使用RasterWorkspaceFactory.openFromFile的方法创建一个Workspace
		RasterWorkspaceFactory pRWF = new RasterWorkspaceFactory();
		String ecliseWorkspace = System.getenv("Eclipse3.6Workspace");
		IWorkspace pWorkspace = pRWF.openFromFile(ecliseWorkspace + "HelloAE" + File.separator
				+ "DataSet" + File.separator + "chap06", 0);
		IRasterWorkspace pRasterWorkspace = new IRasterWorkspaceProxy(pWorkspace);
		//加载输入图层
		IRasterDataset pRasterDataset = pRasterWorkspace.openRasterDataset("nwroads_gd");
		
		//设置输出路径
		ShapefileWorkspaceFactory pSWF = new ShapefileWorkspaceFactory();
		IWorkspace pOutWorkspace = pSWF.openFromFile("c:\\temp", 0);
		
		//转换
		RasterConversionOp pConversionOp = new RasterConversionOp();
		pConversionOp.rasterDataToLineFeatureData((IGeoDataset)pRasterDataset, pOutWorkspace, "roads.shp", true, true, 5000);
		
		ao.shutdown();
		System.out.println("Congratulations!");
	}

}
